-
Notifications
You must be signed in to change notification settings - Fork 277
introduce to_dstring #3110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce to_dstring #3110
Conversation
src/util/dstring.h
Outdated
@@ -209,4 +209,21 @@ struct diagnostics_helpert<dstringt> | |||
} | |||
}; | |||
|
|||
#define DSTRING_NUMBERS_MAX 64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is 64
the optimal number (also, this define should go in util/magic.h
)?
Looks like the CI culprit is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking this as request-changes until the magic-number question is resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR failed Diffblue compatibility checks (cbmc commit: 63d1a57).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87195826
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed Diffblue compatibility checks (cbmc commit: 65891d2).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87883391
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll include it in my profiling, will report back.
@@ -13,4 +13,7 @@ const std::size_t STRING_REFINEMENT_MAX_CHAR_WIDTH = 16; | |||
// Limit the size of strings in traces to 64M chars to avoid memout | |||
const std::size_t MAX_CONCRETE_STRING_SIZE = 1 << 26; | |||
|
|||
// The top end of the range of integers for which dstrings are precomputed | |||
constexpr std::size_t DSTRING_NUMBERS_MAX = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any value in using constexpr
over const
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only that you can then could produce constexpr
dstrings for numbers up to that value from a constexpr
integer.
As std::to_string, to_dstring produces a string from a number. A key feature is that dstrings for values <=64 are pre-computed; generating strings for such numbers is 50x faster than going via std::to_string. int main() { for(unsigned i=0; i<20000000; i++) { dstringt d; int j=20; d=dstringt(std::to_string(j)); } } This is 2.5s as above, and 0.05s with to_dstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: e3f19d2).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/101224713
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On ReachSafety-ControlFlow this optimisation reduces the number of string-table lookups from 62778903 to 27037069 (and the time spent in irept::set(dstringt const&, long long)
from 22.52 seconds to 13.58 seconds).
Many thanks for the benchmarking -- I should really set up some set of benchmarks for this purpose! |
As std::to_string, to_dstring produces a string from a number. A key
feature is that dstrings for values <=64 are pre-computed; generating
strings for such numbers is 50x faster than going via std::to_string.
This is 2.5s as above, and 0.05s with to_dstring.